import request from "@/utils/request"


// 获取所有旅游类型
export function getTravelTypes() {
    return request({
        url: '/api/travelType',
        method: 'get'
    })
}

// 获取城市评论
export function getCommentsByCityId(cityId,type) {
    return request({
        url: `/api/city/comment/getAllByCityId/${cityId}/${type}`,
        method: 'get'
    })
}

// 提交评论回复
export function addCommentReply(replyData) {
    return request({
        url: '/api/city/comment/reply/add',
        method: 'post',
        data: replyData,
        headers: { 'Content-Type': 'application/json;charset=utf-8' }
    })
}

// 添加评论
export function addComment(commentData) {
    return request({
        url: '/api/city/comment/add',
        method: 'post',
        data: commentData,
        headers: { 'Content-Type': 'application/json;charset=utf-8' }
    })
}

export function uploadCommentImages(commentId, files) {
    const formData = new FormData();

    // 添加评论ID
    formData.append('commentId', commentId);

    // 关键：需要单独添加每个文件，使用同一个参数名 'files'
    for (let i = 0; i < files.length; i++) {
        formData.append('files', files[i]);
    }

    return request({
        url: '/api/city/comment/upload/images',
        method: 'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    });
}

// 评论点赞
export function likeComment(commentId, userId) {
    return request({
        url: `/api/city/comment/like/${commentId}/${userId}`,
        method: 'post'
    })
}

// 回复点赞
export function likeReply(replyId, userId) {
    return request({
        url: `/api/city/comment/reply/like/${replyId}/${userId}`,
        method: 'post'
    })
}